package com.ty.springbootshiro.exception;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * GlobalExceptionHandler
 *
 * @aurhor whs
 * @since 2024/10/16
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(UnknownError.class)
    public ModelAndView unauthorizedExceptionHandler(HttpServletRequest request, UnauthorizedException e){ //出现异常后跳转到此方法
        ModelAndView mv = new ModelAndView("403");  //设置跳转路径
        mv.addObject("exception", e);   //将异常信息传到页面
        mv.addObject("url", request.getRequestURL());   //将请求路径传到页面
        return mv;

    }
}
